﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FitbitManager.Subscripters
{
    public class LogManager
    {
        public readonly static string logSubPath = "//Log";
        public readonly static string alertsSubPath = "//Alerts";

        static string alertsPath
        {
            get
            {
                string appPath = Directory.GetCurrentDirectory();
                string logPath = appPath + logSubPath;

                if (!Directory.Exists(logPath))
                    Directory.CreateDirectory(logPath);

                if (!Directory.Exists(alertsPath))
                    Directory.CreateDirectory(alertsPath);
                
                return appPath + alertsSubPath;
            }
        }

        public static void AddLogAlert(string message)
        {
            string filePath = alertsPath + DateTime.Today.ToShortDateString().Replace('/', '-') + ".txt";

            if (!File.Exists(filePath))
            {
                var f = File.Create(filePath);
                f.Close();
            }

            using (StreamWriter sw = File.AppendText(filePath))
            {
                sw.Write(DateTime.Now.ToShortTimeString() + " -> ");
                sw.WriteLine(message);
            }
        }
    }
}
